'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 4_study_configurable_fields.py
* @Time: 2025/10/24
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import ConfigurableField
from langchain_openai import ChatOpenAI
dotenv.load_dotenv()
#1、创建提示词模板
prompt = ChatPromptTemplate.from_template("请生成一个小于{query}的随机整数")

llm = ChatOpenAI(model="gpt-4o-mini" ).configurable_fields(
    temperature = ConfigurableField(
        id="llm_temperature",
        name="大语言温度配置",
        description="用于动态变更模型配置",
    )
)
#3、构建链应用
chain = prompt|llm|StrOutputParser()
#4、调用链
# 正常调用
#content = chain.invoke({"x":100})
#content = chain.invoke({"x":100}, config={"configurable":{"llm_temperature": 0}})
content = chain.with_config(configurable={"llm_temperature": 100}).invoke({"query":100})
print(content)